/**
 * 
 */
package facade;

import java.util.ArrayList;
import java.util.Date;

import metier.*;
import factory.Factory;
import factory.FactoryJDBC;

/**
 * @author Quipu-Team
 *
 */
public class FacadeSeance {
	
	private Factory factory = new FactoryJDBC();
	private Salle salle = null;
	private Seance seance = null;
	private Seance seanceEchange = null;

	public FacadeSeance() {}

	public Salle getSalle() {return salle;}
	public Seance getSeance() {return seance;}
	public Seance getSeanceEchange() {return seanceEchange;}
	
	public void echangerSeance() throws ExceptionMetier {
		seance.echangerSeance(seanceEchange);
	}
	
	public void creerSeanceEchange(Service service, Salle salle, Date periode, int position) {
		seanceEchange = factory.creerSeance(service, salle, periode, position);		
	}
	public void creerSeance(Service service, Salle salle, Date periode, int position) {
		seance = factory.creerSeance(service, salle, periode, position);		
	}
	public void creerSalle(String nom, int capacite) {
		salle = factory.creerSalle(nom, capacite); 
	}
	
	public ArrayList<ElementListe> creerListeSalle() {
		return factory.creerListeSalle(); 
	}
	public ArrayList<ElementListe> creerListeSeance() {
		return factory.creerListeSeance(); 
	}
	public ArrayList<ElementListe> creerListeSeanceSpeciale() throws ExceptionMetier {
		return factory.creerListeSeanceSpeciale(); 
	}
	public ArrayList<Seance> creerListeSeanceSpeciale(Date debut, Date fin) throws ExceptionMetier {
		return factory.creerListeSeanceSpeciale(debut, fin); 
	}
	public ArrayList<Seance> creerListeSeance(int annee, int ue, int enseignant, Date debut, Date fin) throws ExceptionMetier {
		return factory.creerListeSeancePeriode(annee, ue, enseignant, debut, fin); 
	}
	public ArrayList<ElementListe> creerListeSeanceMatiere(int matiere) throws ExceptionMetier {
		return factory.creerListeSeanceMatiere(matiere); 
	}

	
	public void ajouterSeance() throws ExceptionMetier {
		if (seance != null) this.seance.insert();
	}
	
	public void ajouterSalle() throws ExceptionMetier {
		if (salle != null) this.salle.insert();
	}
	
	public void modifierSeance(Service service, Salle salle, Date periode, int position) throws ExceptionMetier {
		this.seance.setService(service);
		this.seance.setSalle(salle);
		this.seance.setDate(periode);
		this.seance.setPosition(position);
		this.seance.update();
	}
	public void modifierSalle(String nom, int capacite) throws ExceptionMetier {
		if (salle.getNom().equals(nom)) {
			this.salle.setCapacite(capacite);
			salle.update();
		}
		else {
			this.salle.delete();
			this.salle = factory.creerSalle(nom, capacite);
			this.salle.insert();
		}
	}
	
	public void supprimerSeance() throws ExceptionMetier {	this.seance.delete(); }
	public void supprimerSalle() throws ExceptionMetier { this.salle.delete(); }
}